package com.hex.ds.hdtp.core.inf.data.contrast.repository.impl;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hex.ds.hdtp.core.inf.common.page.Page;
import com.hex.ds.hdtp.core.inf.common.page.converter.IPageAndMyBatisPlusPageConverter;
import com.hex.ds.hdtp.core.inf.data.contrast.mapper.ICrossDbContrastTaskMapper;
import com.hex.ds.hdtp.core.inf.data.contrast.po.CrossDbContrastRunLogPo;
import com.hex.ds.hdtp.core.inf.data.contrast.po.CrossDbContrastTaskPo;
import com.hex.ds.hdtp.core.inf.data.contrast.repository.ICrossDbContrastTaskRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Package: com.hex.ds.hdtp.core.inf.data.contrast.repository.impl
 * @ClassName CrossDbContrastTaskRepository
 * @Description: 跨库比对任务-数据接口实现类
 * @Author: wz.li
 * @Date 2023/7/24 18:13
 * @Version v2.0.2
 **/
@Component
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class CrossDbContrastTaskRepository implements ICrossDbContrastTaskRepository {

    private final ICrossDbContrastTaskMapper crossDbContrastTaskMapper;

    private final IPageAndMyBatisPlusPageConverter pageConverter;

    /*
     * @Method: queryListByPage <br>
     * @Param: [crossDbContrastTaskPo, toPage] <br>
     * @Return: com.hex.ds.hdtp.core.inf.common.page.Page<com.hex.ds.hdtp.core.inf.data.contrast.po.CrossDbContrastTaskPo> <br>
     * @Description：分页查询<br>
     * @Author： wz.li<br>
     * @Date： 2023/7/24 18:15 <br>
     * @Version： V2.0.2<br>
     */
    @Override
    public Page<CrossDbContrastTaskPo> queryListByPage(CrossDbContrastTaskPo crossDbContrastTaskPo, Page toPage) {
        final IPage tmpPageResult = crossDbContrastTaskMapper.queryListByPage(
                pageConverter.toMyBatisPlusPage(toPage)
                , crossDbContrastTaskPo
        );
        final List list = tmpPageResult.getRecords();
        final Page pageResult = pageConverter.toPage(tmpPageResult);
        return pageResult.setData(list);
    }

    /*
     * @Method: queryList <br>
     * @Param: [crossDbContrastTaskPo] <br>
     * @Return: java.util.List<com.hex.ds.hdtp.core.inf.data.contrast.po.CrossDbContrastTaskPo> <br>
     * @Description：不分页查询<br>
     * @Author： wz.li<br>
     * @Date： 2023/7/24 18:15 <br>
     * @Version： V2.0.2<br>
     */
    @Override
    public List<CrossDbContrastTaskPo> queryList(CrossDbContrastTaskPo crossDbContrastTaskPo) {
        return crossDbContrastTaskMapper.queryList(crossDbContrastTaskPo);
    }

    /*
     * @Method: queryById <br>
     * @Param: [pkId] <br>
     * @Return: com.hex.ds.hdtp.core.inf.data.contrast.po.CrossDbContrastTaskPo <br>
     * @Description：根据主键查询<br>
     * @Author： wz.li<br>
     * @Date： 2023/7/24 18:15 <br>
     * @Version： V2.0.2<br>
     */
    @Override
    public CrossDbContrastTaskPo queryById(String pkId) {
        return crossDbContrastTaskMapper.selectById(pkId);
    }

    /*
     * @Method: add <br>
     * @Param: [crossDbContrastTaskPo] <br>
     * @Return: java.lang.Integer <br>
     * @Description：新增<br>
     * @Author： wz.li<br>
     * @Date： 2023/7/24 18:15 <br>
     * @Version： V2.0.2<br>
     */
    @Override
    public Integer add(CrossDbContrastTaskPo crossDbContrastTaskPo) {
        return crossDbContrastTaskMapper.insert(crossDbContrastTaskPo);
    }

    /**
     * @Method addWithBackPkId
     * @Param
     * @param crossDbContrastTaskPo
     * @Return java.lang.String
     * @Description 新增并返回主键
     * @Author Wang zhihao
     * @Date 2023/8/16 17:40
     * @Version V1.0
     */
    @Override
    public String addWithBackPkId(CrossDbContrastTaskPo crossDbContrastTaskPo) {
        crossDbContrastTaskMapper.insert(crossDbContrastTaskPo);
        return crossDbContrastTaskPo.getPkId();
    }

    /*
     * @Method: modifyById <br>
     * @Param: [crossDbContrastTaskPo] <br>
     * @Return: java.lang.Integer <br>
     * @Description：根据主键更新<br>
     * @Author： wz.li<br>
     * @Date： 2023/7/24 18:16 <br>
     * @Version： V2.0.2<br>
     */
    @Override
    public Integer modifyById(CrossDbContrastTaskPo crossDbContrastTaskPo) {
        return crossDbContrastTaskMapper.updateById(crossDbContrastTaskPo);
    }

    /*
     * @Method: removeById <br>
     * @Param: [pkId] <br>
     * @Return: java.lang.Integer <br>
     * @Description：根据主键删除<br>
     * @Author： wz.li<br>
     * @Date： 2023/7/24 18:16 <br>
     * @Version： V2.0.2<br>
     */
    @Override
    public Integer removeById(String pkId) {
        return crossDbContrastTaskMapper.deleteById(pkId);
    }

    @Override
    public Integer updateStatusById(String pkId,String startTime){
        return crossDbContrastTaskMapper.updateStatusById(pkId,startTime);
    }

    @Override
    public Integer updateEndStatusById(String pkId){
        return crossDbContrastTaskMapper.updateEndStatusById(pkId, DateUtil.now());
    }

    @Override
    public Integer updateCountById(CrossDbContrastRunLogPo recentByTask){
        return crossDbContrastTaskMapper.updateCountById(recentByTask);
    }

    /**
     * @Method modifyTaskFinish
     * @Param pkId
     * @Param status
     * @Return java.lang.Integer
     * @Description 更新比对任务
     * @Author gj.xu
     * @Date 2024/1/11 20:35
     * @Version V2.0
     */
    @Override
    public Integer modifyTaskFinish(String pkId, String status) {
        return crossDbContrastTaskMapper.modifyTaskFinish(pkId, status, DateUtil.now());
    }

}
